﻿<!--
  Extended Silverlight Toolkit - SAMPLE CODE

  Copyright (C) 2010-2012 Xceed Software Inc.

  This program is provided to you under the terms of the Microsoft Public
  License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

  Please purchase a commercial version of this toolkit if you are using
  it in a commercial product. The commercial versions support the project,
  and also include more features for each control, priority support,
  source code, updates, removed watermark, and a proprietary license.

  Visit http://xceed.com and follow @datagrid on Twitter.
-->

<UserControl x:Class="Xceed.Silverlight.DataGrid.Samples.LocalDataAccessSample"
             x:Name="sampleUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:s="clr-namespace:System.ComponentModel;assembly=System.Windows"
             xmlns:sldg="http://schemas.xceed.com/silverlight/xaml/datagrid"
             xmlns:sample="clr-namespace:Xceed.Silverlight.DataGrid.Samples.Shared"
             mc:Ignorable="d"
             d:DesignWidth="640"
             d:DesignHeight="480">
   <UserControl.Resources>
      <ResourceDictionary>

        <Style x:Key="textTrimmingStyle"
                TargetType="TextBlock">
            <Setter Property="TextTrimming"
                    Value="WordEllipsis" />
            <Setter Property="VerticalAlignment"
                    Value="Center" />
        </Style>

        <!-- Converter used to return a BitmapImage from a Country name -->
        <sample:FlagPathConverter x:Key="flagPathConverter" />

        <sldg:ImageConverter x:Key="imageConverter" />

            <!-- DataTemplate to display an Employee object -->
        <DataTemplate x:Key="employeeDataTemplate">
            <Grid MaxHeight="30"
                  VerticalAlignment="Center">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Image Margin="0, 0, 5, 0"
                       Source="{Binding Photo, Converter={StaticResource imageConverter}, NotifyOnValidationError=False, ValidatesOnDataErrors=False}" />

                <StackPanel Grid.Column="1"
                    Orientation="Horizontal"
                    VerticalAlignment="Center">
                    <TextBlock Text="{Binding FirstName, NotifyOnValidationError=False, ValidatesOnDataErrors=False}" />
                    <TextBlock Text=" " />
                    <TextBlock Text="{Binding LastName, NotifyOnValidationError=False, ValidatesOnDataErrors=False}" />
                </StackPanel>
            </Grid>
        </DataTemplate>

        <!-- DataTemplate to display an Employee object from Column.CellContentTemplate-->
        <DataTemplate x:Key="employeeCellContentTemplate">
            <ContentControl ContentTemplate="{StaticResource employeeDataTemplate}"/>
        </DataTemplate>

        <!-- DataTemplate to display a Country -->
        <DataTemplate x:Key="countryDataTemplate">
            <StackPanel Orientation="Horizontal"
                VerticalAlignment="Center"
                Margin="5,0,0,0">
                <!--The flagPathConverter resource changes the value of a
                        group (e.g., "Canada") to an image. -->
                <Image MaxHeight="15"
                       Margin="0, 0, 5, 0"
                       Source="{Binding Converter={StaticResource flagPathConverter}}" />

                <TextBlock Text="{Binding}"
                           TextTrimming="WordEllipsis"
                           VerticalAlignment="Center" />
            </StackPanel>
        </DataTemplate>

            <!-- DataTemplate to display a Country from Column.CellContentTemplate -->
        <DataTemplate x:Key="countryCellContentTemplate">
            <ContentControl ContentTemplate="{StaticResource countryDataTemplate}"/>
        </DataTemplate>

        <!-- DataTemplate to display the DateTime as Short DateTime -->
        <DataTemplate x:Key="shortDateDataTemplate">
            <TextBlock Text="{Binding StringFormat=\{0:d\}}"
                VerticalAlignment="Center" />
        </DataTemplate>

          <!-- DataTemplate to display the DateTime as Short DateTime from Column.CellContentTemplate -->
        <DataTemplate x:Key="shortDateCellContentTemplate">
            <ContentControl ContentTemplate="{StaticResource shortDateDataTemplate}"/>
        </DataTemplate>

        <!-- DataTemplate to display the $ in Freight column -->
        <DataTemplate x:Key="freightDataTemplate">
            <TextBlock Text="{Binding StringFormat=\{0:C\}}"
                VerticalAlignment="Center" />
        </DataTemplate>

        <!--  DataTemplate to display the $ in Freight column from Column.CellContentTemplate -->
        <DataTemplate x:Key="freightCellContentTemplate">
            <ContentControl ContentTemplate="{StaticResource freightDataTemplate}"/>
        </DataTemplate>

        </ResourceDictionary>
   </UserControl.Resources>

   <sldg:DataGridControl x:Name="dataGrid"
                         ItemsSource="{Binding}"
                         RowHeight="36">

      <!-- Add a NotificationControl to the FixedFooters so that messages sent will be displayed. -->
      <sldg:DataGridControl.FixedFooters>
         <sldg:NotificationControl />
      </sldg:DataGridControl.FixedFooters>

      <sldg:DataGridControl.Columns>
         <sldg:Column FieldName="OrderID"
                      ReadOnly="True"
                      Title="Order"
                      Width="100"
                      CellHorizontalContentAlignment="Left"
                      CellContentStyle="{StaticResource textTrimmingStyle}" />

         <sldg:Column FieldName="Employee"
                      Title="Employee"
                      Width="140"
                      CellHorizontalContentAlignment="Left"
                      CellContentTemplate="{StaticResource employeeCellContentTemplate}"/>

         <sldg:Column FieldName="Customer.CompanyName"
                      Title="Customer"
                      Width="185"
                      ReadOnly="True"
                      CellHorizontalContentAlignment="Left" />

         <sldg:Column FieldName="ShipCountry"
                      Title="Country"
                      CellContentTemplate="{StaticResource countryCellContentTemplate}" />

         <sldg:Column FieldName="ShipCity"
                      Title="City"
                      Width="80"
                      CellContentStyle="{StaticResource textTrimmingStyle}" />

         <sldg:Column FieldName="ShipAddress"
                      Title="Address"
                      CellContentStyle="{StaticResource textTrimmingStyle}"
                      Width="200" />

         <sldg:Column FieldName="ShipPostalCode"
                      Title="Postal Code"
                      Width="120"
                      CellContentStyle="{StaticResource textTrimmingStyle}" />

         <sldg:Column FieldName="OrderDate"
                      Title="Order Date"
                      Width="120"
                      CellContentTemplate="{StaticResource shortDateCellContentTemplate}" />

         <sldg:Column FieldName="RequiredDate"
                      Title="Required Date"
                      Width="140"
                      CellContentTemplate="{StaticResource shortDateCellContentTemplate}" />

         <sldg:Column FieldName="ShippedDate"
                      Title="Shipped Date"
                      Width="140"
                      CellContentTemplate="{StaticResource shortDateCellContentTemplate}" />

         <sldg:Column FieldName="Shipper.CompanyName"
                      Title="Shipper"
                      ReadOnly="True"
                      CellHorizontalContentAlignment="Left"
                      Width="155" />

         <sldg:Column FieldName="Freight"
                      Width="100"
                      CellContentTemplate="{StaticResource freightCellContentTemplate}" />

         <!-- Do not display the ShipName amd ShipRegion columns. -->
         <sldg:Column FieldName="ShipName"
                      Visible="False" />

         <sldg:Column FieldName="ShipRegion"
                      Visible="False" />

         <sldg:Column FieldName="EmployeeID"
                      Visible="False" />

         <sldg:Column FieldName="CustomerID"
                      Visible="False" />

         <sldg:Column FieldName="Customer"
                      Visible="False" />

         <sldg:Column FieldName="ShipVia"
                      Visible="False" />

         <sldg:Column FieldName="Shipper"
                      Visible="False" />

        </sldg:DataGridControl.Columns>

   </sldg:DataGridControl>
</UserControl>
